package com.dengyin2000.javaeye.ordering.action;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.datamodel.DataModel;

import com.dengyin2000.javaeye.ordering.entity.SnackShop;

@Name("chooseShopAction")
@Scope(value=ScopeType.SESSION)
public class ChooseShopAction implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8568401959944163862L;
	
	
	@DataModel
	private List<SnackShop> shops;
	
	@In(value="orderingDatabase")
	Session session;
	
	public void fetchShops() {
		if (shops == null || shops.isEmpty()) {
			Query query = session.createQuery("from SnackShop order by name");
			shops = query.list();
		}
	}
}
